package com.group6.converter;

import java.util.Stack;
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View;
import android.text.Editable;
import android.text.TextWatcher;

public class BinAdd extends Activity implements TextWatcher {
	EditText txtBinary, txtBinary1;
    TextView txtBinary2;
    
	@Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.binadd);
        txtBinary=(EditText)findViewById(R.id.txtBinary);
        txtBinary1=(EditText)findViewById(R.id.txtBinary1);
        txtBinary2=(EditText)findViewById(R.id.txtBinary2);
        txtBinary.addTextChangedListener(this);
        txtBinary1.addTextChangedListener(this);
    }
	
    public void beforeTextChanged(CharSequence sequence,int start,int count,int after){
    }
    
    public void afterTextChanged(Editable editable){
    }
    
    public void onTextChanged(CharSequence sequence,int start,int before,int count){
    	calculate(txtBinary, txtBinary1, txtBinary2);
    }
    
    public void calculate(TextView txtView, TextView txtView1, TextView txtView2)
    {
    	if(txtBinary.getText().toString().trim().length()==0)
        {
            txtView.setText("");
            return;
        }
    	
    	if(txtBinary1.getText().toString().trim().length()==0)
        {
            txtView.setText("");
            return;
        }
    	String a = txtBinary.getText().toString();
    	String b = txtBinary1.getText().toString();
    	int number0 = Integer.parseInt(a);
    	int number1 = Integer.parseInt(b);
    	
    	int sum = number0 + number1;
    	String s3 = Integer.toBinaryString(sum);
    	txtView2.setText(s3.toString());
    }
}

